package com.rui.study.micro.scheduler.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.dangdang.ddframe.job.executor.ShardingContexts;
import com.dangdang.ddframe.job.lite.api.listener.ElasticJobListener;
import com.rui.study.micro.scheduler.service.BulletinService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: study_20180903
 * @description:
 * @author: Yaowr
 * @create: 2018-10-30 15:52
 **/
@Component
public class BulletinJob implements SimpleJob, ElasticJobListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(BulletinJob.class);

    @Autowired
    private BulletinService bulletinService;


//    public BulletinJob() {
//        super(1000, 1000);
//    }

    @Override
    public void execute(ShardingContext context) {
        String threadName = Thread.currentThread().getName();
        String jobName = context.getJobName();
        String taskId = context.getTaskId();
        int shardingItem = context.getShardingItem();
        LOGGER.info("[" + threadName + "]---[" + jobName +"]---[" + taskId + "]---[" + shardingItem + "]---");


    }

//    @Override
//    public void doBeforeJobExecutedAtLastStarted(ShardingContexts shardingContexts) {
//
//    }
//
//    @Override
//    public void doAfterJobExecutedAtLastCompleted(ShardingContexts shardingContexts) {
//        bulletinService.clearTask(shardingContexts.getJobName());
//    }

    @Override
    public void beforeJobExecuted(ShardingContexts shardingContexts) {

    }

    @Override
    public void afterJobExecuted(ShardingContexts shardingContexts) {
        bulletinService.clearTask(shardingContexts.getJobName());
    }
}
